package com.happy.zebra.admin.controller;

import com.shycloud.mido.common.core.util.R;
import com.shycloud.mido.common.util.QRCodeUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Base64;

@RestController
@AllArgsConstructor
@RequestMapping("/h5extension")
public class H5ExtensionController {

    @GetMapping("/getQRCode")
    @ResponseBody
    public R getQRCode() throws IOException{
        BufferedImage buffer = QRCodeUtil.getExtensionCode("http://admin.joymido.com", 300);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ImageIO.write(buffer, "jpg", bos);
        Base64.Encoder encoder = Base64.getEncoder();
        String result = encoder.encodeToString(bos.toByteArray());
        return new R<>(result);
    }
}